package Synchronized_1;
class Counter {
    private static int count = 0;

    public static synchronized void increment() {
        int temp = count + 1;
        try {
            Thread.sleep(5); // 模拟处理时间
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        count = temp;
        System.out.println(Thread.currentThread().getName() + " 当前计数: " + count);
    }
}

public class 静态方法同步 {
    public static void main(String[] args) {
        // 创建30个计数线程
        for (int i = 0; i < 30; i++) {
            new Thread(new Runnable() {
                public void run() {
                    Counter.increment();
                }
            }, "计数线程-" + i).start();
        }
    }
}